package com.goodving.guli.database;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/* renamed from: cn.com.smartdevices.bracelet.d.w */
class C0876w extends SQLiteOpenHelper {
    private static C0876w f4449a = null;
    private static final String f4450b = "exercises_db";
    private static final int f4451c = 1;
    private static final String f4452d = "exercises";
    private static final String f4453e = "_id";
    private static final String f4454f = "subtype";
    private static final String f4455g = "type";
    private static final String f4456h = "desc";
    private static final String f4457i = "mets";

    static {
        f4449a = null;
    }

    public C0876w(Context context) {
        super(context, f4450b, null, f4451c);
    }

    private SQLiteDatabase m8998a(boolean z) {
        if (!z) {
            return getReadableDatabase();
        }
        try {
            return getWritableDatabase();
        } catch (Exception e) {
            close();
            return z ? getWritableDatabase() : getReadableDatabase();
        }
    }

    public static C0876w m8999a() {
        return f4449a;
    }

    public static void m9000a(Context context) {
        if (f4449a == null) {
            f4449a = new C0876w(context);
        }
    }

    public double m9001a(String str) {
        String[] strArr = new String[f4451c];
        strArr[0] = f4457i;
        String[] strArr2 = new String[f4451c];
        strArr2[0] = str;
        Cursor query = m8998a(false).query(f4452d, strArr, "desc=?", strArr2, null, null, null);
        if (query == null) {
            return 0.0d;
        }
        try {
            double d = (query.getCount() == 0 || !query.moveToFirst()) ? 0.0d : query.getDouble(query.getColumnIndex(f4457i));
            if (query == null) {
                return d;
            }
            query.close();
            return d;
        } catch (Throwable th) {
            if (query != null) {
                query.close();
            }
        }
        return 0.0d;
    }

    public void m9002b() {
        m8998a(true).execSQL("DELETE FROM exercises");
    }

    public void onCreate(SQLiteDatabase sQLiteDatabase) {
        sQLiteDatabase.execSQL("CREATE TABLE IF NOT EXISTS exercises(_id INTEGER PRIMARY KEY AUTOINCREMENT, uuid INTEGER, type INTEGER DEFAULT -1, subtype INTEGER DEFAULT -1, desc TEXT, mets DOUBLE, reserved1 TEXT, reserved2 TEXT, reserved3 TEXT, reserved4 TEXT, reserved5 TEXT, reserved6 TEXT, reserved7 TEXT, reserved8 TEXT, reserved9 TEXT, reserved10 TEXT, reserved11 TEXT, reserved12 TEXT, reserved13 TEXT, reserved14 TEXT, reserved15 TEXT, reserved16 TEXT, reserved17 TEXT, reserved18 TEXT, reserved19 TEXT, reserved20 TEXT);");
    }

    public void onDowngrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
    }

    public void onUpgrade(SQLiteDatabase sQLiteDatabase, int i, int i2) {
    }
}
